'use strict';

const extend = require('extend');

module.exports = {

      /**
     * Json way to output.
     * @public
     * @param {String} message
     * @param {Object} data
     * @param {Integer} statusCode
     * @param {String} message
     */
  json(data, statusCode = 200, statusText = null) {
    this.header['Content-type'] = 'application/json';
    this.status = statusCode;
    this.body = data;
    if (statusText) { this.message = statusText; }
  },

    /**
     * Output an normal formatted data after operate success.
     * @param {Mixed} data the output data
     * @param {String} appended message
     */
  success(data, message = null) {
    this.json(extend({ message }, data), 200);
  },

    /**
     * Output an unusual formatted data, normally after operate failed.
     * @param {String} message error message
     * @param {Number} statusCode
     * @param {String} statusText
     */
  fail(message, statusCode, statusText = null) {
    this.json({ message }, statusCode, statusText);
  },
};

